<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      const orders = [
        {
          id: 1,
          name: 'John Smith',
          address: '123 Main St',
          status: 'created',
          log: [
            {
              status: 'created',
              time: '2023-02-16 12:30:00',
            },
          ],
        },
        {
          id: 2,
          name: 'Jane Doe',
          address: '456 Second St',
          status: 'packed',
          log: [
            {
              status: 'created',
              time: '2023-02-16 10:00:00',
            },
            {
              status: 'packed',
              time: '2023-02-16 12:30:00',
            },
          ],
        },
        {
          id: 3,
          name: 'Bob Johnson',
          address: '789 Third St',
          status: 'shipped',
          log: [
            {
              status: 'created',
              time: '2023-02-16 10:00:00',
            },
            {
              status: 'packed',
              time: '2023-02-15 12:00:00',
            },
            {
              status: 'shipped',
              time: '2023-02-16 9:00:00',
            },
          ],
        },
      ]

      //1.getOrdersByStatus(status: string): 该函数接受一个参数status,返回一个包含所有状态为status的订单的数组。其中，订单的每个对象应该包含以下属性：

      // - **id**
      // - **name**
      // - **address**
      // - **status**
      // - **log**: 只包含状态为**status**的日志对象 并且按照订单的**id**从小到大排序。

      // function getOrdersByStatus(status) {
      //   let arr = []
      //   orders.forEach(function (item) {
      //     if (item.status === status) {
      //       let obj = item
      //       obj.log = item.log.filter(function (items) {
      //         return items.status === status
      //       })
      //       arr.push(obj)
      //     }
      //   })
      //   return arr
      // }
      // console.log(getOrdersByStatus('shipped'))

      //2
      // function getOrderStatusHistory(id) {
      //   let obj = {}
      //   orders.forEach(function (item) {
      //     if (item.id === id) {
      //       item.log.sort(function (a, b) {
      //         return +new Date(a.time) - +new Date(b.time)
      //       })
      //       obj = item
      //     }
      //   })
      //   return obj
      // }

      // console.log(getOrderStatusHistory(3))
    </script>
  </body>
</html>
